package com.inspinia.message.common.util;

import com.inspinia.base.util.HttpClientUtil;
import com.inspinia.base.util.JsonUtils;
import com.inspinia.message.common.model.Notice;
import com.inspinia.message.common.properties.MpushConfig;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 消息推送的请求工具类
 *
 * @author wangjun
 * @date 2018/4/27
 */
public class AppMessagePush {
    /**
     * 推送消息到Mpush端进行推送
     *
     * @param userId
     * @param notice
     * @return
     */
    public static void pushMessageToApp(Long userId, Notice notice) {
        String requestUrl = "http://" + MpushConfig.MPUHS_IP +":"+ MpushConfig.MPUHS_PORT + "/push";
        Map<String, String> requestMap = new ConcurrentHashMap<>(2);
        requestMap.put("userId", "user-" + String.valueOf(userId));
        requestMap.put("content", JsonUtils.toJson(notice));

        String requestJson = JsonUtils.toJson(requestMap);
        try {
            HttpClientUtil.postJson(requestUrl, requestJson, null);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
